require(['../config'], () => {
    require(['template', 'header', 'footer'], (template) => {
        class list2 {
            constructor() {
                this.getinfo();
                this.search();
                this.Cscreen();
                this.Pscreen();
                this.siteSearch();
            }

            getinfo() {
                $.get('http://rap2api.taobao.org/app/mock/241085/list2', resp => {
                    if (resp.code === 200) {
                        const list = resp.body
                        var html = template('uuuu', { list })
                        $('#getshop').html(html)
                    }
                })
            }
            Cscreen() {
                $('.zhpx').on('click', () => {
                    $('#getshop li').remove()
                    $.get('http://rap2api.taobao.org/app/mock/241085/list2', resp => {
                        if (resp.code === 200) {
                            const list = resp.body
                                // console.log(list)
                            list.sort(function(a, b) {
                                return a.shopName.localeCompare(b.shopName)
                            })
                            var html = template('uuuu', { list })
                            $('#getshop').html(html)
                        }

                    })
                })
            }

            Pscreen() {
                $('.jgpx').on('click', () => {
                    $('#getshop li').remove()
                    $.get('http://rap2api.taobao.org/app/mock/241085/list2', resp => {
                        if (resp.code === 200) {
                            const list = resp.body
                            console.log(list)
                            list.sort(function(a, b) {
                                return a.shopPrice - b.shopPrice
                            })
                            var html = template('uuuu', { list })
                            $('#getshop').html(html)
                        }

                    })
                })
            }

            //搜索框
            search() {
                $('#seek').on('click', () => {
                    $('.hot').css("top", "100px").css("left", "50%")
                    $('.mm').css("display", "none")
                    $('main').css("display", "block").css("opacity", "1")
                    $('#ul').css("display", 'none')
                })
            }
            siteSearch() {
                let ul = document.querySelector('#ul')
                let input = document.querySelector('#input')
                ul.onmousedown = function(e) {
                    let target = e.target;
                    if (target.tagName === "LI") {
                        input.value = target.innerHTML
                    }
                }
                input.onblur = function() {
                    ul.innerHTML = ''
                }

                function fn1(resp) {
                    let {
                        s
                    } = resp;
                    ul.innerHTML = '';
                    s.forEach(item => {
                        let li = document.createElement('li');
                        li.innerHTML = item;
                        ul.appendChild(li);
                    })
                }
                input.onkeyup = function() {
                    let wd = this.value;
                    $.getJSON(`https://www.baidu.com/su?wd=${wd}&cb=?`, function fn(data) {
                        let s = data.s;
                        s = s.splice(0, 5);
                        $(ul).html("")
                        s.forEach(item => {
                            $("<li>").html(item).appendTo(ul);
                        })
                    })
                }
            }

        }
        new list2()
    })
})